package com.biz.primus.ms.promotion.trans;

import com.biz.primus.base.vo.promotion.PromotionProductVo;
import com.biz.primus.model.promotion.vo.SpecialOfferProductVo;
import com.biz.primus.ms.promotion.dao.po.SpecialOfferPromotionProduct;
import com.google.common.collect.Lists;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * SpecialOfferPromotionProductPo --> SpecialOfferProductVo
 *
 * @author david-liu
 */
public class SpecialOfferPromotionProductPo2VoMapper implements Function<SpecialOfferPromotionProduct, SpecialOfferProductVo> {
    @Override
    public SpecialOfferProductVo apply(SpecialOfferPromotionProduct specialOfferPromotionProduct) {
        return new SpecialOfferProductVo();
    }

    public SpecialOfferProductVo map(SpecialOfferPromotionProduct specialOfferPromotionProduct, PromotionProductVo promotionProductVo) {
        if (Objects.isNull(specialOfferPromotionProduct) || Objects.isNull(promotionProductVo)) {
            return null;
        }
        SpecialOfferProductVo vo = new SpecialOfferProductVo();
        vo.setProductId(specialOfferPromotionProduct.getProductId());
        vo.setProductName(promotionProductVo.getProductName());
        vo.setProductCode(promotionProductVo.getProductCode());
        vo.setPurchaseQuantityLimit(specialOfferPromotionProduct.getPurchaseQuantityLimit());
        vo.setSpecialOfferPrice(specialOfferPromotionProduct.getSpecialOfferPrice());
        vo.setCategoryId(promotionProductVo.getCategoryId());
        vo.setCategoryName(promotionProductVo.getCategoryName());
        vo.setBrandName(promotionProductVo.getBrandName());
        vo.setBrandId(promotionProductVo.getBrandId());
        return vo;
    }

    public List<SpecialOfferProductVo> mapWithList(Collection<SpecialOfferPromotionProduct> specialOfferPromotionProducts, Map<Long, PromotionProductVo> promotionProductVoMap) {
        return Optional.ofNullable(specialOfferPromotionProducts).orElse(Lists.newArrayList()).stream().map(specialOfferPromotionProduct -> this.map(specialOfferPromotionProduct, promotionProductVoMap.get(specialOfferPromotionProduct.getProductId()))).collect(Collectors.toList());
    }
}
